package com.bbm.communitysystem.core.redis;

import com.bbm.communitysystem.domain.Per;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PerRedis {
    /**
     * key的组成 per_ + per的path
     * 例：
     *      /user/all
     *  key = per_/user/all
     */
    private final String key = "per_";

    private final RedisTemplate<String, Per> redisTemplate;

    @Autowired
    public PerRedis(@Qualifier("per") RedisTemplate<String, Per> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public void setValue(String keys, Per value) {
        redisTemplate.opsForValue().set(key + keys, value);
    }

    public Per getValue(String keys) {
        return redisTemplate.opsForValue().get(key + keys);
    }

}
